package com.practice.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SortText {

	private static final String FILE_PATH = "";
	
	public static void main(String[] args) {
		List<String> lineList = new ArrayList<>();
		
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(FILE_PATH));
			String line;
			while ((line = reader.readLine()) != null) {
				lineList.add(line);
			}
		} catch (IOException ex) {
			ex.printStackTrace();
			return;
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}
		}
		
		lineList.sort((String o1, String o2) -> o1.compareTo(o2));
		
		BufferedWriter writer = null;
		try {
			writer = new BufferedWriter(new FileWriter(FILE_PATH));
			for (String line : lineList) {
				writer.write(line);
				writer.newLine();
			}
			writer.flush();
		} catch (IOException ex) {
			ex.printStackTrace();
			return;
		} finally {
			if (writer != null) {
				try {
					writer.close();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}
		}
	}

}